<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in" ref="dialogBox">
      <div class="cornerComment-in-title">
        <span>{{ listName }}-评分项</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <div class="hearder-search">
          <el-col :span="24" class="breadcrumb-container input-val-box">
            <el-button type="primary" size="small" @click="detailId=0,detailVisible=true">新增评测项</el-button>
            <el-button size="small" @click="InitFn"><i class="el-icon-refresh"></i>刷新</el-button>
            <span class="allbook">总 {{ page.total }} 条数据</span>
          </el-col>
        </div>
        <el-table
            ref="multipleTable"
            :data="arryList"
            border
            :height="tableHeight"
            tooltip-effect="dark"
            style="width: 100%"
            header-cell-class-name="table-text-c"
            cell-class-name="table-text-c">
          <el-table-column
              prop="id"
              label="ID"
              align="center"
              width="90">
          </el-table-column>
          <el-table-column
              prop="name"
              label="名称"
              align="center">
          </el-table-column>
          <el-table-column
              prop="type"
              label="类型"
              align="center">
            <template slot-scope="scope">
              {{ Number(scope.row.type) == 1 ? '计时' : '数值' }}
            </template>
          </el-table-column>
          <el-table-column
              prop="description"
              label="描述"
              align="center">
          </el-table-column>
          <el-table-column
              label="操作"
              align="center"
              width="180">
            <template slot-scope="scope">
              <el-button size="small" @click="detailId=scope.row.id,detailVisible=true" type="primary" plain>编辑
              </el-button>
              <el-button size="small" @click="handleDetel(scope.row.id)" type="danger" plain>删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-col :span="24" class="toolbar">
          <el-pagination
              background
              layout="total,prev, pager, next"
              :total="page.total"
              :page-size="page.pagesize"
              @current-change="handleSizeChange">
          </el-pagination>
        </el-col>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click="closePOpup" size="small">返回</el-button>
      </div>
    </div>
    <detail :visible.sync="detailVisible" detailType="2" :detailId="detailId" @InitFn="InitFn"
            :cateId="listId"></detail>
  </div>
</template>

<script>
import {pagination} from '@/utils/util.js'
import {assessIndex, assessDelete} from "@/api/admin/evaluating"
import detail from "./detail";

export default {
  props: ['visible', 'listId', 'listName'], // commoent 学生点评 collection 学生采集
  components: {
    detail
  },
  data() {
    return {
      dialogVisible: false,
      arryList: [],
      // 设置table页面分页所需
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      tableHeight: 0,
      detailVisible: false,
      detailId: 0
    }
  },
  watch: {
    visible() {
      let n = this;
      this.dialogVisible = this.visible
      if (this.visible) {
        this.$nextTick(() => {
          let height = n.$refs.dialogBox.offsetHeight;  //top 50 1 search 50 page 50 10 footer 50 1
          n.tableHeight = height - (51 + 50 + 50 + 51)
        })
        this.InitFn()
      } else {
        this.page = {
          pageindex: pagination.pageIndex,
          pagesize: pagination.pageSize,
          total: pagination.total
        }
        this.arryList = []
      }
    }
  },
  created() {
  },
  methods: {
    handleSizeChange(val) {
      this.page.pageindex = val
    },
    // 获取记录
    InitFn() {
      assessIndex({p: this.page.pageindex, cate_id: this.listId}).then(res => {
        this.arryList = res.list.data
        this.page.total = res.list.total
      })
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    handleDetel(id) {
      this.$confirm('确认永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.detelRespon(id)
      }).catch(() => {
      })
    }
    ,
    detelRespon(id) {
      assessDelete({id: id}).then(res => {
        if (!res.code) {
          this.$message(res.msg)
          this.InitFn()
        }
      })
    }
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 80%;
  height: 600px;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 0 10px 10px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.hearder-search {
  display: flex;
  align-items: center;
}
</style>


